package com.fzebu.fastboot.util;

import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;

/**
 * @author Y-Aron
 * @version 1.0.0
 * @create 2019/9/27 17:10
 */
public class ModeUtil {

    private static final int DEFAULT_CHEATER = 1;

    public static void resetDataShare(int moduleId, String tableName) {
        resetDataShare(moduleId, tableName, null);
    }

    public static void resetDataShare(int modeId, String tableName, String modeUuid) {
        if (modeId <= 0 || StringUtils.isEmpty(tableName)) {
            return;
        }
        String sql = StringUtils.isEmpty(modeUuid) ? "SELECT MAX(ID) ID FROM " + tableName
                : "SELECT ID FROM " + tableName + " WHERE MODEUUID='"+ modeUuid +"'";
        RecordSet rs = new RecordSet();
        rs.execute(sql);
        if (rs.next()) {
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(DEFAULT_CHEATER, modeId, rs.getInt("ID"));
        }
    }
}
